< previous page page_383 next page >

Page 383
By defining the exposure of the properties and methods of a class, the developer can define the safe behavior of the object without relying on external sources.
Polymorphism
Different classes can contain methods and properties of the same name. As such, working with these different objects becomes very easy. You no longer need to memorize the different calls for each object; instead, you can always make the same call, just to different objects. For example, two classes, clsEllipse and clsSquare, may both have Paint methods, but calling each ones Paint method causes different and obvious results. From a design point of view, the application that uses these objects is not concerned about how or what the objects paint, it just wants them to paint. Because the methods have the same name, the interface to both objects is very easy to use and remember.
Testing
Because classes define discrete, encapsulated behavior, its easier to test the class as a whole than it is to test the system as a whole. The term unit testing fits better with object-oriented programming than with any other programming method. This is not to say that system testing is not required. Its just easier to test the robustness of a class than it is a set of unrelated code that may have to be called in a specific sequence.
Code Reusability
Because classes should be designed as self-contained units, they can be shared between projects very easily. All the data as well as the routines that operate on that data are encapsulated in the class definition; therefore, name conflicts with other routines and variables isnt a concern. Adding an existing class to a project is as simple as adding the appropriate CLS file.
Disadvantages of OOP
Of course, not all of OOP is nice and rosy. Like any programming method, it does have its drawbacks. Lets discuss some of the disadvantages to OOP.

 
< previous page page_383 next page >

If you like this book, buy it!